/**
 * @author admin
 */
public class Tank {
    /**
     *     坦克横坐标
     */
    private int x;
    /**
     * 坦克纵坐标
     */
    private int y;
    /**
     * 方向
     */
    private int direct = 0;

    public int getSpeed() {
        return speed;
    }

    private int speed = 10;

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public void moveUp(){
        y-=speed;
    }
    public void moveDown(){
        y+=speed;
    }
    public void moveLeft(){
        x-=speed;
    }
    public void moveRight(){
        x+=speed;
    }

    public void setDirect(int direct) {
        this.direct = direct;
    }

    public int getDirect() {
        return direct;
    }

    public Tank(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public void setX(int x) {
        this.x = x;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    /**
     *     判断超过范围
     */
    public void outOfRange(){
        try {
            int max = 15;
            int width = 650;
            int height = 950;
            if (y > width || y < 0){
                if (y < 0){
                    direct =2;
                    for (int i = 0; i <= max; i++){
                        moveDown();
                        Thread.sleep(100);
                    }
                }else{
                    direct =0;
                    for (int i = 0; i <= max; i++){
                        moveUp();
                        Thread.sleep(100);
                    }
                }
            }else if (x>height || x < 0){
                if (x < 0){
                    direct =1;
                    for (int i = 0; i <= max; i++){
                        moveRight();
                        Thread.sleep(100);
                    }
                }else{
                    direct =3;
                    for (int i = 0; i <= max; i++){
                        moveLeft();
                        Thread.sleep(100);
                    }
                }
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
